import Ember from 'ember';
import ListViewMinxin from 'emberworkspace/mixins/list-view-mixin';

export default Ember.Controller.extend(ListViewMinxin, {
  pageTitle: "树结构管理",
  pageSubTitle: "树状对象的管理，比如用户组，文件目录等",
  modelName: "tree",
  menus: Ember.computed(function() {
    var cm = this.get('commonMenus');
    return [cm[0], cm[1], cm[2], {
      name: "treenode",
      action: "treenode",
      label: "编辑树节点",
      showWhen: "one"
    }];
  }),
  actions: {
    menuClicked(mname) {
      if (mname === 'treenode') {
        var modellist = this.get('model'),
          selected = modellist.find((it) => {
            return it.get('isSelected');
          });
        if (selected.get('isFullLoaded')) {
          this.transitionToRoute("treenodes.index.children", selected, selected.get('treeJson').root);
        } else {
          this.transitionToRoute("treenodes.index.children", selected.get('id'), "-1");
        }
      } else {
        this.defaultMenuHandler(mname);
      }
    }
  }
});
